<template>
  <div class="app-container">
    <el-divider>
      服务协议
    </el-divider>
    <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="120px"
             style="width: 100%;"
    >
      <el-row :gutter="40" class="panel-group">
        <el-col :xs="24" :sm="24" :lg="24" class="card-panel-col">
<!--          <vue-ueditor-wrap v-model="temp.content" :config="myConfig"/>-->
          <Tinymce ref="editor" v-model="temp.content" :height="600"/>
        </el-col>
      </el-row>
    </el-form>
    <el-divider>
      <el-button type="primary" @click="createData">
        保存
      </el-button>
    </el-divider>
  </div>
</template>

<script>
import { detail, create } from '@/api/introduce'
import Tinymce from '@/components/Tinymce'
// import { getMenus } from '@/api/menu'
import VueUeditorWrap from 'vue-ueditor-wrap'

export default {
  name: 'IntroduceService',
  components: { VueUeditorWrap, Tinymce },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'info',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      // myConfig: {
      //   autoHeightEnabled: false,
      //   initialFrameHeight: 300,
      //   initialFrameWidth: '90%',
      //   serverUrl: '/admin/UEditor/php/controller.php',
      //   UEDITOR_HOME_URL: '/admin/UEditor/'//build 路径
      //   // UEDITOR_HOME_URL: '/UEditor/' //调试路径
      // },
      preventSumit: false,
      progressFactor: 0.96,
      uploadProgress: 0,
      headers: {},
      imagecropperShow: false,
      imagecropperKey: 0,
      menus: [],
      roles: [],
      list: null,
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        keyword: ''
      },
      temp: {
        id: undefined,
        content: '',
        type:1
      },
      dialogFormVisible: false,
      dialogStatus: '',
      textMap: {
        update: '编辑',
        create: '创建'
      },
      filterText: '',
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      rules: {
        name: [{ required: true, message: '身份不能为空', trigger: 'change' }]
      }

    }
  },
  watch: {
    filterText(val) {
      this.$refs.tree.filter(val)
    }
  },
  created() {
    this.getList()
  },
  methods: {
    cropSuccess(resData) {
      this.imagecropperShow = false
      this.imagecropperKey = this.imagecropperKey + 1
      this.temp.avatar = resData.url
    },
    close() {
      this.imagecropperShow = false
    },
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    getCheckedNodes() {
      console.log(this.$refs.tree.getCheckedNodes())
    },
    setCheckedNodes(row) {
      this.$refs.tree.setCheckedNodes(row)
    },

    getList() {
      this.listLoading = true
      detail(1).then(response => {
        this.temp = response.data
      })
    },
    resetForm() {
      this.dialogFormVisible = false
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          create(this.temp).then(response => {
            // this.list.unshift(this.temp)
            this.dialogFormVisible = false
            if (response.code == 200) {
              this.$notify.success({
                title: '成功',
                message: response.msg,
                type: 'success',
                duration: 2000
              })
              this.resetTemp()
              this.getList()
            } else {
              this.$notify.error({
                title: '失败',
                message: response.msg,
                duration: 2000
              })
            }
          })
        }
      })
    },
    resetTemp() {
      this.temp = {
        id: undefined,
        content: '',
        type:1
      }
    }
  }
}
</script>

<style scoped>
.edit-input {
  padding-right: 100px;
}

.cancel-btn {
  position: absolute;
  right: 15px;
  top: 10px;
}
</style>
<style scoped>
.avatar {
  width: 200px;
  height: 200px;
  border-radius: 50%;
}
</style>
<style>
.amap-page-container {
  height: 400px;
  padding-top: 20px;
}

.inpu {
  width: calc(100% - 120px);
  margin-right: 20px;
  margin-bottom: 20px;
  margin-left: 20px;
}

.wan {
  margin-top: 20px;
}
</style>
